home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 1 / LSD Compendium Deluxe 1.iso / a / programming / assembly / mapping.lha / ChunkyTextureMapping.doc next >
Encoding:
Text File  |  1994-01-31  |  5.1 KB  |  211 lines

  1. [totally incomplete and incomprehensible version... oh well better than
  2.  nothing maybe... James]
  3.  
  4. TEXTURE MAPPING
  5.  
  6.  
  7.   This document contains some ideas on a simple form of linear texture mapping,
  8.   where a walk is made along a line in a source pixelmap to obtain a scanline
  9.   for a texture mapped polygon.
  10.  
  11.            A     l'           B
  12.         +----.--------+
  13.             |   .         |
  14.             |   .         |
  15.             |  .          |
  16.             |  .          |
  17.             | .           |
  18.             | .           |
  19.             |.            |
  20.             |.            |
  21.            l.             |
  22.             |             |
  23.             +-------------+
  24.            D           C
  25.  
  26.  
  27.     In the above diagram, we walk along ll' picking off pixels to generate
  28.     a texture mapped scan line thru the projection of ABCD.
  29.  
  30.  
  31. Some ideas for speedups:
  32.  
  33.   Early work does not consider any coherence between pixels on ll', with future
  34. analysis it might be possible to utilitize some coherence.  This might be achieved
  35. by storing a number of copies of ABCD with either different rotations, different
  36. pre-zoomed images, and possibly an alternate method of storing the pixmap (such
  37. as storing a sub-rectangle of 4 adjacent pixels in one word).
  38.     
  39.   One possible speedup... suppose we store 36 pre-rotated copies of each pixmap,
  40. then it might be possible to cheat by mapping two pixels at once, or maybe up
  41. to four pixels at once... depending on the size+distortion of the mapped polygon.
  42. These pixels could be horizontally adjacent... or possibly map a 4x4 square of
  43. pixels at once.  It might be possible to get the blitter to depack these 4x4 squares
  44. during a chunky2planar conversion.
  45.  
  46.  
  47. INITIAL IDEAS AT STEPPING ACROSS ll'
  48.  
  49. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  50.  
  51. IDEA
  52.  
  53.     ;; ideally the simplest approach is
  54.     add.w/l    d0,a0        8
  55.     move.b    (a0),(a1)+    8
  56.  
  57.     ;where our image is super scaled in both X and Y directions.
  58.  
  59. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  60.  
  61. IDEA
  62.  
  63.     ;; D<f> = | x-frac | y-int | y-frac | x-int |
  64.  
  65.     addx.w    D<delta-f>,D<f>      4    add delta to step along line
  66.     move.w    D<f>,D<tmp>      4    make copy
  67.     and.w    D<mask>,D<tmp>      4    mask off integer increment needed
  68.     eor.w    D<tmp>,D<f>      4    clear integer overflow from delta-f
  69.     add.w    D<tmp>,a0      8    adjust pointer to src
  70.     move.b    (a0),(a1)+      8    pick off source pixel
  71.  
  72.     ;; replace last two with:
  73.     ;; move.b (a0,D<tmp>),(a1)+ 14  saves 2 cycles.
  74.  
  75.     ;Example:
  76.     ;  d<f> = | 6 bits | 2 bits | 6 bits | 2 bits |
  77.     ; D<mask> = %000000 11 000000 11
  78.  
  79.  
  80. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  81.  
  82. IDEA
  83.  
  84.     ;; Have image Y-scaled 2^n times.
  85.     
  86.     addx.l    d0,d1        8
  87.     move.b    (a0,d1.w),(a1)+    14
  88.  
  89.     ; d1 =  | x-frac |      | y-int+frac | x-int |
  90.     
  91.     ; y-scaling means the fractional part of y-int+frac is effectively
  92.     ; ignored in the pixel look up [or we can have a special filtered zoomed
  93.         ; image... maybe for better looking zoom in/outs
  94.  
  95. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  96.  
  97. IDEA
  98.  
  99.     ;; as Y=scaled... but use mask to avoid y-scaling.  instead we have
  100.     ;; all the different pixmaps interleaved (or sparse pix maps).
  101.  
  102.     addx.l    d0,d1            8    add delta
  103.     move.w    d1,d2            4    
  104.     and.w    d3,d2            4    mask of y-fraction
  105.     move.b    (a0,d2.w),(a1)+        14    pick off pixel
  106.  
  107. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  108.  
  109. IDEA
  110.  
  111.     
  112.     ;; cube-o-matic [note it has severe register constraints... so subtract
  113.     ;; at least two swaps... to be fair.
  114.  
  115.     moveq    #0,d6
  116.     add.w a6,d5
  117.     addx.w    d6,d5
  118.  
  119.     swap    d5
  120.     move.l    a6,d6
  121.     swap    d6
  122.     add.w    d6,d5
  123.     move.w    d5,d6
  124.     swap    d5
  125.     move.b    d5,d6
  126.  
  127.     move.b    0(a0,d6.w),...
  128.  
  129. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  130.  
  131. IDEA
  132.  
  133.     add.w    dfi,df
  134.     addx.w    DI,d6
  135.     move.w    dm,dt
  136.     and.w    df,dt
  137.     add.w    dt,d6
  138.     move.b    0(a0,d6.w),....
  139.  
  140. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  141.  
  142. IDEA
  143.     ;; Z.b = xint
  144.     ;; X.l = |xf| |y|yf
  145.     add.l    delta,X        ;8
  146.     addx.b    blah,Z        ;4
  147.     move.w    X,t        ;4
  148.     move.b    Z,t        ;4
  149.  
  150. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  151.  
  152. IDEA
  153.  
  154.         |x y|<-|x y|+d|x y|            4
  155.     d6  |Y X|<-|Y X|+d|Y X|+carry        4
  156.     move.w    dm,dt    ;            4
  157.     and.w    df,dt    ;            4
  158.     eor.w    dt,df    ;            4
  159.     add.w    dt,d6    ; mask off y overflow bit and add it on.  4
  160.  
  161. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  162.  
  163. IDEA
  164.  
  165.     things to remember:
  166.  
  167.     move.l    d0,a0; move.b (a0),(a1)+    is a possibility
  168.                         move.l d0,a0 only takes 4 cycles
  169.  
  170.     add    Rn,Rn     any combo
  171.     addx    Dn,Dn    data registers only.
  172.  
  173. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  174.  
  175. IDEA
  176.  
  177.     add.w    ddf,df
  178.     move.w    dm,dt
  179.     and.w    df,dt
  180.     eor.w    dt,df
  181.     addx.w    dI,dt
  182.     add.l    dt,a0
  183.     move.b    (a0),...
  184.  
  185. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  186.  
  187. IDEA
  188.  
  189.     ; d0 = |objectptr| |y|x|
  190.     add.w    d1,d2
  191.     
  192.     addx.w    DI,d0
  193.     move.w    d0,a0        ;4
  194.     move.b    (a0),...    ;8
  195.  
  196.  
  197. IDEA -- VERY NASTY -- 68000 only
  198.  
  199.     addx.l    d0,d1        ; 8 cycles.... add delta
  200.     move.l    d1,a0        ; 4 cycles
  201.     move.b    (a0),...    ; 8 cycles... top 8 bits masked for free
  202.  
  203. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  204.  
  205. IDEA
  206.     addx.l    d0,d1    8
  207.     move.w    dm,d2    4
  208.     and.w    d1,d2    4
  209.     move.l    d2,a0    4
  210.     move.b    (a0),...8
  211.